﻿using System;
using System.Configuration;
using System.Web.Configuration;
using System.Text;

namespace VioletDevelopmentLaboratory.Net.Web.Configuration
{
	public sealed class GlobalizationSectionManager : ConfigurationManagerBase
	{
		private GlobalizationSection section;

		public GlobalizationSectionManager()
		{
			this.section = (GlobalizationSection)base.GetConfigurationSection("system.web/globalization");
		}

		public void Modify(string culture, string uiCulture, Encoding requestEncoding, Encoding responseHeaderEncoding, Encoding responseEncoding, Encoding fileEncoding, bool enableBestFitResponseEncoding, bool enableClientBasedCulture, string resourceProviderFactoryType)
		{
			if (string.IsNullOrEmpty(culture))
			{
				culture = "";
			}
			if (string.IsNullOrEmpty(uiCulture))
			{
				uiCulture = "";
			}
			this.section.Culture = culture;
			this.section.UICulture = uiCulture;

			this.section.RequestEncoding = requestEncoding;
			this.section.ResponseHeaderEncoding = responseHeaderEncoding;
			this.section.ResponseEncoding = responseEncoding;
			this.section.FileEncoding = fileEncoding;

			this.section.EnableBestFitResponseEncoding = enableBestFitResponseEncoding;
			this.section.EnableClientBasedCulture = enableClientBasedCulture;

			this.section.ResourceProviderFactoryType = resourceProviderFactoryType;

			this.Save();
		}

		public GlobalizationSection GetGlobalization()
		{
			return this.section;
		}
	}

}